import { defineStore } from 'pinia'
import { addPost, detail, getpostList, remove ,updatePost,removeBatchByPostIds} from '@/service/post/index.js'
import getDate from '@/utils/dateChange.js'
import responseMessage from '@/utils/response.js'

const postStore = defineStore('post', {
  state: () => ({
    postList: '',
    detail: ''
  }),
  actions: {
    //获取帖子列表
    async getpostsList(page, size, searchParams) {
    const res = await getpostList(page, size, searchParams)
    console.log('回传的帖子信息结果集是===',res)
    this.postList = res.data
    console.log('postList结果集是===',this.postList)
    },
    //新增帖子信息
    async addpost(addpost) {
      const res = await addPost(addpost)
      //responseMessage(res)
      return res
    },
    //修改帖子信息
    async updatePosts(post) {
      console.log('修改帖子信息',post)
      const res = await updatePost(post)
      console.log('修改完了')
      //responseMessage(res)
      return res
    },
    //删除帖子  
    async removePostById(id) {
      const res = await remove(id)
      responseMessage(res)
    },
    //批量删除帖子信息
    async removeBatchByPostsIds(attrIds) {
      console.log('批量删除帖子信息ids',attrIds)
      const res = await removeBatchByPostIds(attrIds)
      responseMessage(res)
    },
    //帖子详情
    async getPostDetail(id) {
      console.log('准备查询了')
      const res = await detail(id)
      console.log('详情信息是===',res)
      this.detail = res.data.data
      //responseMessage(res)
      return res
    }
  }
})

export default postStore
